#include "scene.h"

#include "octree.h"

Scene::Scene()
{
}

Scene::~Scene(){
    QList<Object*>::iterator iter;
    iter = m_objects.begin();
    while(m_objects.size() > 0){
        delete (*iter);
        m_objects.removeFirst();
        iter = m_objects.begin();
    }
}

Object* Scene::get_object(int pos){
    if((pos >= 0) && (pos < m_objects.size())){
        return m_objects[pos];
    }else{
        return NULL;
    }
}

Octree* Scene::get_octree(int pos){
    if((pos >= 0) && (pos < m_octrees.size())){
        return m_octrees[pos];
    }else{
        return NULL;
    }
}

int Scene::get_num_objs(){
    return m_objects.size();
}

void Scene::add_object(Object *obj){
    m_objects.push_back(obj);
}

void Scene::add_octree(Octree *tree){
    m_octrees.push_back(tree);
}

void Scene::subdivide_octrees(){
    QList<Octree*>::iterator tree_iter;
    Octree *tree;
    for(tree_iter = m_octrees.begin(); tree_iter != m_octrees.end(); tree_iter++){
        tree = (*tree_iter);
        tree->subdivide(this);
    }
}

void Scene::delete_object(int pos){
    m_objects.removeAt(pos);
}

void Scene::delete_octree(int pos){
    m_octrees.removeAt(pos);
}
